package com.emm.yixun.mobile.ui.customer;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.emm.yixun.mobile.R;
import com.emm.yixun.mobile.adapter.FoucsAdapter;
import com.emm.yixun.mobile.application.EmmApplication;
import com.emm.yixun.mobile.base.BaseActivity;
import com.emm.yixun.mobile.model.GetDictionaryList.RqBusNumList;

/**
 * 
 * <p>
 * <b>Title：</b> 关注重点
 * </p>
 * <p>
 * <b>Description：</b>
 * </p>
 * 
 * @author tangxin
 * @date 2016年12月6日 下午4:13:07
 */
public class FocusActivity extends BaseActivity {

	TextView title_main;
	ImageView back_btn;
	ListView listView_s;
	FoucsAdapter adapter;
	Button sure_btn, cancel_btn;

	/** 侧滑关闭框架 */
	// private SwipeBackLayout mSwipeBackLayout;

	List<String> listid = new ArrayList<String>();

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.guanzhu_activity);

		// SetSwipeBackLayout(mSwipeBackLayout);

		BaseActivity.activity = this;

		InitView();

		SetRelativiLayoutPadding(R.id.main_head_top_rela);

		InitBtn();

	}

	@Override
	protected void onResume() {
		super.onResume();
		BaseActivity.activity = this;
	}

	/**
	 * <p>
	 * <b>Title：</b> 获取已选中的ID
	 * </p>
	 * <p>
	 * <b>Description：</b>
	 * </p>
	 * 
	 * @author tangxin
	 * @date 2017年2月24日 上午10:38:13
	 */
	private void getListId(ArrayList<RqBusNumList> RqFocus) {
		for (int i = 0; i < RqFocus.size(); i++) {
			if (RqFocus.get(i).isSelect())
				listid.add(RqFocus.get(i).getDictionaryId());
		}
	}

	/**
	 * 
	 * <p>
	 * <b>Title：</b> 初始化view
	 * </p>
	 * <p>
	 * <b>Description：</b>
	 * </p>
	 * 
	 * @author tangxin
	 * @date 2016年12月7日 下午2:20:30
	 */
	private void InitView() {
		title_main = (TextView) findViewById(R.id.title_main);
		title_main.setText("关注重点");
		back_btn = (ImageView) findViewById(R.id.back_btn);
		cancel_btn = (Button) findViewById(R.id.cancel_btn);
		listView_s = (ListView) findViewById(R.id.listView_s);
		sure_btn = (Button) findViewById(R.id.sure_btn);
	}

	private void InitBtn() {
		back_btn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				CanlcelData();
				finish();
			}
		});
		cancel_btn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				CanlcelData();
				finish();
			}
		});
		getListId(EmmApplication.RqFocus);
		adapter = new FoucsAdapter(FocusActivity.this, EmmApplication.RqFocus);
		listView_s.setAdapter(adapter);
		sure_btn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}

	private void CanlcelData() {
		for (int i = 0; i < EmmApplication.RqFocus.size(); i++) {
			EmmApplication.RqFocus.get(i).setSelect(false);
		}
		for (int j = 0; j < listid.size(); j++) {
			for (int i = 0; i < EmmApplication.RqFocus.size(); i++) {
				if (listid.get(j).equals(EmmApplication.RqFocus.get(i).getDictionaryId())) {
					EmmApplication.RqFocus.get(i).setSelect(true);
				}
			}
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			CanlcelData();
			finish();
		}
		return super.onKeyDown(keyCode, event);
	}

}
